package jmu.cultural_tourism.service.impl;

import jmu.cultural_tourism.entity.CityProvince;
import jmu.cultural_tourism.dao.CityProvinceDao;
import jmu.cultural_tourism.service.CityProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;


/**
 * 省份表(CityProvince)表服务实现类
 *
 * @author makejava
 * @since 2025-07-20 16:17:39
 */
@Service("cityProvinceService")
public class CityProvinceServiceImpl implements CityProvinceService {
    @Autowired
    private CityProvinceDao cityProvinceDao;

    /**
     * 通过ID查询单条数据
     *
     * @param provinceId 主键
     * @return 实例对象
     */
    @Override
    public CityProvince queryById(Integer provinceId) {
        return this.cityProvinceDao.queryById(provinceId);
    }

    /**
     * 分页查询
     *
     * @param cityProvince 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @Override
    public Page<CityProvince> queryByPage(CityProvince cityProvince, PageRequest pageRequest) {
        long total = this.cityProvinceDao.count(cityProvince);
        return new PageImpl<>(this.cityProvinceDao.queryAllByLimit(cityProvince, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param cityProvince 实例对象
     * @return 实例对象
     */
    @Override
    public CityProvince insert(CityProvince cityProvince) {
        this.cityProvinceDao.insert(cityProvince);
        return cityProvince;
    }

    /**
     * 修改数据
     *
     * @param cityProvince 实例对象
     * @return 实例对象
     */
    @Override
    public CityProvince update(CityProvince cityProvince) {
        this.cityProvinceDao.update(cityProvince);
        return this.queryById(cityProvince.getProvinceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param provinceId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer provinceId) {
        return this.cityProvinceDao.deleteById(provinceId) > 0;
    }
}
